// 选项卡
let lis=document.querySelectorAll(".banner .Tab-Control>ul>li");
let divs=document.querySelectorAll(".banner .Tab-Control>ul>li>div");
for(let i=0;i<lis.length;i++){
    lis[i].addEventListener("mouseenter",function(){
        lis[i].classList.add("active");
        divs[i].classList.add("son")
    })
    lis[i].addEventListener("mouseleave",function(){
        lis[i].classList.remove("active");
        divs[i].classList.remove("son")
    })
    
}


//轮播图
let select = document.querySelectorAll(".slideshow p a");
let show = document.querySelectorAll(".slideshow .imgs img");
let slideshow = document.querySelector(".slideshow");
let sl = document.querySelector(".slideshow .sl");
let sr = document.querySelector(".slideshow .sr");
let times;

for (let i = 0; i < select.length; i++) {
    select[i].addEventListener("mouseenter", function () {
        index = i;
        play(index);
    })
}

let index = 0;

function playtimes() {
    times = setInterval(function () {
        index++;
        if (index == show.length) {
            index = 0;
        }
        play(index);
    }, 2000)
}

playtimes();


//移入到大盒子就停止
slideshow.addEventListener("mouseenter", function () {
    clearInterval(times);
})
slideshow.addEventListener("mouseleave", function () {
    playtimes();
})


sl.addEventListener("click", function () {
    index--;
    if (index < 0) {
        index = show.length - 1;
    }
    play(index);
})
sr.addEventListener("click", function () {
    index++;
    if (index > 3) {
        index = 0;
    }
    play(index);
})

function play(index) {
    for (let j = 0; j < select.length; j++) {
        select[j].classList.remove("select");
        show[j].classList.remove("show");
    }
    select[index].classList.add("select");
    show[index].classList.add("show");
}


// 图书选项卡
let as=document.querySelectorAll(".books .books-left p a");
let sons=document.querySelectorAll(".books .books-left>div");
for(let i=0;i<as.length;i++){
    as[i].addEventListener("mouseenter",function(){
        for(let j=0;j<as.length;j++){
            as[j].classList.remove("active");
            sons[j].classList.remove("books-left-son")
        }
        as[i].classList.add("active")
        sons[i].classList.add("books-left-son")
    })
}



// 回到顶部
let tops=document.querySelector("#top");
let roof=document.querySelector(".roof");
tops.addEventListener("click",function(){
   let sy=window.scrollY;
    let times=setInterval(function(){
        sy=sy-50;
        window.scrollTo(0,sy);
        if(sy<=0){
            clearInterval(times);
            window.scrollTo(0,0);
        }
    },50)
    
})
window.onscroll=function(){
    let sy=window.scrollY;
    if(sy>=500){
        tops.style.display="block";
        roof.style.display="block";
    }else{
        tops.style.display="none";
        roof.style.display="none";
    }
}




// 侧边栏
$(".floorbox li").hover(function(){
    $(this).css({
        "background-position-x":-40,
        "backgroundColor":$(this).attr("bgcolor"),
        "width":40
    });
}
,
function(){
    $(this).css({
        "background-position-x":0,
        "background-color":"",
        "width":0
    });
}
)

$(".floorbox li").click(function(){
    let index=$(this).index();
    let top=$(".conjunct").eq(index).offset().top;
    $("html,body").stop().animate({scrollTop:top},1000)
    })


// 小广告
$("#mouse").hover(function(){
    $("#mouses").css("display","block")
},
function(){
    $("#mouses").css("display","none")
}
)